package com.itheima.easy.controller;// Import necessary packages and classes

import com.itheima.easy.base.AjaxResult;
import com.itheima.easy.dto.BedDto;
import com.itheima.easy.entity.Bed;
import com.itheima.easy.service.BedService;
import com.itheima.easy.vo.BedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bed")
@Api(tags = "床位管理相关接口")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    @PostMapping("/create")
    @ApiOperation(value = "创建床位", notes = "传入床位对象，包括床位号和所属房间号")
    public AjaxResult createBed(@RequestBody BedDto bed) {
        bedService.addBed(bed);
        return AjaxResult.success("Bed created successfully");
    }

    @GetMapping("/read/{id}")
    @ApiOperation(value = "根据id查询床位", notes = "传入床位id")
    public AjaxResult readBed(@PathVariable("id") Long id) {
        BedVo bed = bedService.getBedById(id);
        return AjaxResult.success(bed);
    }

    @PutMapping("/update")
    @ApiOperation(value = "更新床位", notes = "传入床位对象，包括床位id、床位号、所属房间号等信息")
    public AjaxResult updateBed(@RequestBody BedDto bed) {
        bedService.updateBed(bed);
        return AjaxResult.success("Bed updated successfully");
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除床位", notes = "传入床位id")
    public AjaxResult deleteBed(@PathVariable("id") Long id) {
        bedService.deleteBedById(id);
        return AjaxResult.success("Bed deleted successfully");
    }

    @GetMapping("/read/room/{roomId}")
    @ApiOperation(value = "根据房间id查询床位", notes = "传入房间id")
    public AjaxResult<List<Bed>> readBedByRoomId(@PathVariable("roomId") Long roomId) {
        List<BedVo> beds = bedService.getBedsByRoomId(roomId);
        return AjaxResult.success(beds);
    }
}

